const { ccclass, property } = cc._decorator;

@ccclass
export default class AdapterBg extends cc.Component {
    onLoad() {
        cc.view.setResizeCallback(this.resizeView.bind(this));
        this.resizeView();
    }
    resizeView() {
        /**设计尺寸 */
        let design_size_o = cc.Canvas.instance.designResolution;
        let nSize = this.node.getContentSize();
        /**真实尺寸 */
        let frame_size_o = cc.view.getFrameSize();
        //判断是按宽还是高进行缩放
        let scaleW = design_size_o.width / frame_size_o.width;
        let scaleH = design_size_o.height / frame_size_o.height;
        let realW = 0;
        let realH = 0;
        if (scaleW > scaleH) {
            realW = design_size_o.width;
            realH = frame_size_o.height * scaleW;
        } else {
            realW = frame_size_o.width * scaleH;
            realH = design_size_o.height;
        }
        let nscale = realW / nSize.width > realH / nSize.height ? realW / nSize.width : realH / nSize.height;
        this.node.setScale(nscale);
    }
}
